/*
 * @Author: i@douxuefeng.cn
 * @Date: 2023-01-07 00:34:46
 * @LastEditTime: 2023-01-07 17:18:28
 * @LastEditors: i@douxuefeng.cn
 * @Description:
 * @FilePath: /iris-api/Volumes/Data/jobs/go-utils/wechat/mp/params/base_msg.go
 */
package params

import "encoding/xml"

type BaseMsg struct {
	ToUserName   string `xml:"ToUserName"`
	FromUserName string `xml:"FromUserName"`
	CreateTime   int64  `xml:"CreateTime"`
	MsgType      string `xml:"MsgType"`
	MsgId        int64  `xml:"MsgId"`
	MsgDataId    string `xml:"MsgDataId"`
	Idx          int    `xml:"Idx"`
	Content      string `xml:"Content"`
	PicUrl       string `xml:"PicUrl"`
	MediaId      string `xml:"MediaId"`

	Format       string `xml:"Format"`
	ThumbMediaId string `xml:"ThumbMediaId"`

	Location_X string `xml:"Location_X"`
	Location_Y string `xml:"Location_Y"`
	Scale      string `xml:"Scale"`
	Label      string `xml:"Label"`

	Title       string `xml:"Title"`
	Url         string `xml:"Url"`
	Description string `xml:"Description"`

	Event    string `xml:"Event"`
	EventKey string `xml:"EventKey"`
	Ticket   string `xml:"Ticket"`

	// EventLocation
	Latitude  string `xml:"Latitude"`
	Longitude string `xml:"Longitude"`
	Precision string `xml:"Precision"`
}
type CDATA string

func (c CDATA) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	return e.EncodeElement(struct {
		string `xml:",cdata"`
	}{string(c)}, start)
}

type Article struct {
	XMLName     xml.Name `xml:"item"`
	Title       string   `xml:"Title"`
	Description string   `xml:"Description"`
	PicUrl      string   `xml:"PicUrl"`
	Url         string   `xml:"Url"`
}

type BaseMsgReply struct {
	XMLName      struct{} `xml:"xml"`
	ToUserName   string   `xml:"ToUserName"`
	FromUserName string   `xml:"FromUserName"`
	CreateTime   int64    `xml:"CreateTime"`
	MsgType      string   `xml:"MsgType"`
	// text消息
	Content CDATA `xml:"Content,omitempty"`
	// image消息
	Image struct {
		MediaId string `xml:"MediaId"`
	} `xml:"Image,omitempty"`
	// voice消息
	Voice struct {
		MediaId string `xml:"MediaId"`
	} `xml:"Voice,omitempty"`
	// video消息
	Video struct {
		MediaId     string `xml:"MediaId"`
		Title       string `xml:"Title"`
		Description string `xml:"Description" `
	} `xml:"Video,omitempty"`
	// music 消息
	Music struct {
		Title        string `xml:"Title"`
		Description  string `xml:"Description"`
		MusicUrl     string `xml:"MusicUrl"`
		HQMusicUrl   string `xml:"HQMusicUrl"`
		ThumbMediaId string `xml:"ThumbMediaId"`
	} `xml:"Music,omitempty"`
	// news消息
	ArticleCount int        `xml:"ArticleCount"`
	Articles     *[]Article `xml:"Articles>Article"`
}
